# -*- coding: utf-8 *-*

#   This file is part of Sql-Rice.
#
#    Sql-Rice is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Sql-Rice is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Sql-Rice; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

import unittest
import sql_parse
import gui
import serialization
import json
from rules.valide.text import rut


class TestControls(unittest.TestCase):

    def setUp(self):
        with open('clientes.dd') as f:
            json_string = f.read()
        json_obj = json.loads(json_string)
        self.data_dict = serialization.from_json(json_obj)

    def test_create_control_rule(self):
        r = gui.create_widget_info('rut', 'clientes', self.data_dict)
        self.assertEqual(r.name, 'rut')
        self.assertEqual(r.rules[0].length, 12)
        self.assertEqual(r.widget, gui.backend.base.TEXT)

    def test_create_control_validator(self):
        r = gui.create_widget_info('rut', 'clientes',
                         self.data_dict, valide=[rut])

        assert r.name == 'rut'
        assert r.rules[0].length == 12
        assert r.validators[0] == rut
        assert r.widget == gui.backend.base.TEXT
